import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Demo2 {
    public static void main(String[] args) {

        //先新建一个Collection 对象


        //添加数据
        Collection collection =new ArrayList();
        Student s1=new Student("张三",20);
        Student s2=new Student("李四",18);
        Student s3=new Student("王五",22);

        collection.add(s1);
        collection.add(s2);
        collection.add(s3);

        System.out.println("元素个数"+collection.size());

        System.out.println(collection.toString());


        //删除数据
        collection.remove(s1);
        System.out.println(collection);

        //3.1遍历
        //增强for 遍历

        for (Object object:collection)
        {
            Student s=(Student) object;

            System.out.println(object);
            System.out.println(s);
        }

        //迭代器遍历
        System.out.println("--------迭代器遍历---------");
        Iterator iterator=collection.iterator();

        while (iterator.hasNext())
        {
            System.out.println((Student)iterator.next());
        }

        System.out.println(collection.contains(s2));


    }
}
